/*

Author   : chaos

FileName : rec_sum.cpp

Date     : 09/08/17 17:39:38

*/
#include <iostream>
using namespace std;

int recursion_sum(int up_value);
int loop_sum(int up_value);
int main(int argc ,char *argv[])
{
    cout << " The sum form 1 to 5 is " << recursion_sum(5) << " . (recursion)" << endl;

    cout << "The sum from 1 to 5 is "  << loop_sum(5) << ".(loop)" << endl;
    return 0;
}

int recursion_sum(int up_value){
    if(up_value > 1)
        return (up_value + recursion_sum(up_value - 1));
    else
        return 1;
}


int loop_sum(int up_value)
{
    int i,sum;

    for(i = up_value,sum = 0; i>=1; i--)
        sum += i;

    return sum;
}
